﻿using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using PBOffice.Models;
using PBOffice.BLL;


public partial class AppraisalManager_AttendanceStatistics : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ListItem lll = new ListItem();
            lll.Text = "请选择";
            this.ddlMonth.Items.Insert(0, lll);
            this.AspNetPager1.PageSize = 9;
            this.AspNetPager1.RecordCount = new StaffExpManager().GetCount("", "");
            this.GridView1.DataSource = new NameNumOverOff().GetByNameAndNum("", "", this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize);
            this.GridView1.DataBind();
        }


    }
    ////一个月内的总加班小时数OverWork
    ////一个月内的请假的小时数OffWork
    //protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    //{
    //    if (e.Row.RowType == DataControlRowType.DataRow)
    //    {
    //        string name = e.Row.Cells[0].Text;
    //        string month = e.Row.Cells[1].Text;
    //        Label offCount = new Label();
    //        offCount.ID = "lbOff";
    //        offCount.Text = GetOffWorkContHours(month, name).ToString(); ;
    //        Label overCount = new Label();
    //        overCount.ID = "lbOver";
    //        overCount.Text = GetOverWorkContHours(month, name).ToString();
    //        e.Row.Cells[2].Controls.Add(offCount);
    //        e.Row.Cells[3].Controls.Add(overCount);

    //    }

    //}
   
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string name = this.txtName.Text.Trim();
        string month = this.ddlMonth.Text;
        if (name.Length==0)
        {
            name = "";
        }
        if (this.ddlMonth.Text == "请选择")
        {
             month ="";
        }
             
        this.AspNetPager1.RecordCount = new StaffExpManager().GetCount(month,name);
        this.GridView1.DataSource = new NameNumOverOff().GetByNameAndNum(month, name, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize);
        this.GridView1.DataBind();
    }
    protected void btnCheck_Click(object sender, EventArgs e)
    {
        string name = this.txtName.Text.Trim();
        string month = this.ddlMonth.Text.Trim();
        if (name.Length == 0)
        {
            name = "";
        }
        if (this.ddlMonth.Text == "请选择")
        {
            month = "";
        }
        this.AspNetPager1.RecordCount = new StaffExpManager().GetCount(month, name);
        this.GridView1.DataSource = new NameNumOverOff().GetByNameAndNum(month, name, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize);
        this.GridView1.DataBind();
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "tongji")
        {
            GridViewRow dv = (GridViewRow)(((ImageButton)(e.CommandSource)).Parent.Parent);
            string name = GridView1.Rows[dv.RowIndex].Cells[0].Text;
            int num = Convert.ToInt32(GridView1.Rows[dv.RowIndex].Cells[1].Text);
            string off = GridView1.Rows[dv.RowIndex].Cells[2].Text;
            string over =GridView1.Rows[dv.RowIndex].Cells[3].Text;
            Response.Redirect(string.Format("AppraisalPicture.aspx?num={0}&name={1}&off={2}&over={3}",num,name,off,over));

        }
    }
}
//public class GridviewTemplate : ITemplate
//{
//  public delegate void EventHandler(object sender, EventArgs e);  
//         public event EventHandler eh;  

//         private DataControlRowType templateType;  

//         private string columnName;  
//         private string controlID;  



//         public GridViewTemplate(DataControlRowType type, string colname)  

//         {  

//             templateType = type;  

//             columnName = colname;  

//         }  
//         public GridViewTemplate(DataControlRowType type,string controlID, string colname)  
//         {  
//             templateType = type;  
//             this.controlID = controlID;  
//             columnName = colname;  
//         }  


//   public void InstantiateIn(System.Web.UI.Control container)   
//    {  
//        switch (templateType)  
//        {  
//            case DataControlRowType.Header:  
//                Literal lc = new Literal();  
//                lc.Text = columnName;  
//                container.Controls.Add(lc);  
//                break;  
//            case DataControlRowType.DataRow:              
//                LinkButton lbtn = new LinkButton();  
//                lbtn.ID = this.controlID;  
//                if (eh != null)  
//                {  
//                    lbtn.Click += new System.EventHandler(eh);  
//                }  
//                lbtn.DataBinding+=new System.EventHandler(lbtn_DataBinding);  

//                container.Controls.Add(lbtn);  

//                break;  
//            default:  
//                break;  
//        }  
//    }  
//     void lbtn_DataBinding(object sender, EventArgs e)  
//     {  
//         LinkButton lbtn = sender as LinkButton;  
//         if (lbtn != null)  
//         {  
//             GridViewRow container = lbtn.NamingContainer as GridViewRow;  
//             if (container != null)  
//             {  
//                 object dataValue = DataBinder.Eval(container.DataItem, columnName);  
//                 if (dataValue != DBNull.Value)  
//                 {  
//                     lbtn.Text = dataValue.ToString();  
//                 }  
//             }  
//         }  
//     }  

//}